<script setup>
import { Plus } from "@element-plus/icons-vue";
import useTable from "@/utils/useTable";
import {http} from "@/api";
import {ref} from "vue";
/**
 * 表格
 * @type {Ref<UnwrapRef<*[]>>}
 */
const {
  searchParams,
  pageNo,
  pageSize,
  total,
  changePage,
  changeSize,
  dataSource,
  search,
  reset,
  openAdd,
  openEdit,
  openDelete
} = useTable({
  requestFn: http.deviceData,
  routerPre: 'deviceData',
  params: {
    device_id: '',
    member_id: '',
    start_time: '',
    end_time: ''
  }
})
const deviceList = ref([])
const memberList = ref([])
// 获取设备列表
http.device.list().then(res => {
  deviceList.value = res.data
})

// 获取用户列表
http.member.list().then(res => {
  memberList.value = res.data
})
</script>
<template>
  <PageMain title="设备数据管理">
    <el-form label-suffix="：" inline>
      <el-form-item label="设备">
        <el-select clearable v-model="searchParams.device_id" placeholder="请选择设备">
          <el-option
              v-for="item in deviceList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="用户">
        <el-select clearable v-model="searchParams.member_id" placeholder="请选择所属用户">
          <el-option
              v-for="item in memberList"
              :key="item.id"
              :label="item.nickname"
              :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间">
        <el-date-picker
            v-model="searchParams.start_time"
            type="date"
            placeholder="选择日期时间"
            value-format="YYYY-MM-DD"
            format="YYYY-MM-DD"
        />
      </el-form-item >
      <el-form-item label="结束时间">
        <el-date-picker
            v-model="searchParams.end_time"
            type="date"
            placeholder="选择日期时间"
            value-format="YYYY-MM-DD"
            format="YYYY-MM-DD"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="add-box">
      <el-button type="primary" :icon="Plus" @click="openAdd">添加</el-button>
    </div>
    <div class="table-box">
      <el-table :data="dataSource">
        <el-table-column width="180px" label="生成时间" prop="publish_time"></el-table-column>
        <el-table-column label="设备" prop="device.name"></el-table-column>
        <el-table-column label="用户" prop="member.nickname"></el-table-column>
        <el-table-column label="氢气浓度" prop="hydrogen_concentration"></el-table-column>
        <el-table-column label="温度" prop="temperature"></el-table-column>
        <el-table-column label="湿度" prop="humidity"></el-table-column>
        <el-table-column label="生态液" prop="ecological_liquid"></el-table-column>
        <el-table-column label="运行状态" prop="run_status"></el-table-column>
        <el-table-column label="清洗状态" prop="clean_status"></el-table-column>
        <el-table-column label="氢气" prop="hydrogen"></el-table-column>
        <el-table-column label="硫化氢" prop="hydrogen_sulfide"></el-table-column>
        <el-table-column label="甲酸醇" prop="methanol"></el-table-column>
        <el-table-column label="甲流二醇" prop="ethylene_glycol"></el-table-column>
        <el-table-column label="乙胺" prop="ethylamine"></el-table-column>
        <el-table-column label="吲哚" prop="indole"></el-table-column>
        <el-table-column label="更新时间" prop="updated_time"></el-table-column>
        <el-table-column label="操作" fixed="right" width="120">
          <template #default="scope">
            <el-button type="text" @click="openEdit(scope.row)">编辑</el-button>
            <el-button type="text" @click="openDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          v-model:current-page="pageNo"
          v-model:page-size="pageSize"
          :page-sizes="[10, 50, 100, 200]"
          background
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="changeSize"
          @current-change="changePage"
      />
    </div>
  </PageMain>
</template>

<style scoped lang="scss">

</style>
